/**
 * Copyright 2009 Wisdom
 */
package com.wisdom.model.entities;

import java.util.Set;

import javax.persistence.*;

/**
 * Entity represent of post category in system
 * 
 * @author alekseiko
 * @since 1.0
 */
@Entity
@Table(name="WE_CATEGORIES")
public class Category {
    
    private long id;
    private String category;
    private Set<Post> posts;
    
    /**
     * Default constructor
     */
    public Category() {	
    }

    /**
     * Constructor initialize all fields
     * 
     * @param id - unique category id
     * @param category - category text
     * @param posts - all posts for this is category
     */
    public Category(long id, String category, Set<Post> posts) {
	this.id = id;
	this.category = category;
	this.posts = posts;
    }

    /**
     * Get category id
     * 
     * @return the id
     */
    @Id
    @Column(name = "WE_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public long getId() {
        return id;
    }

    /**
     * Set category id
     * 
     * @param id - unique category id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Get category text
     * 
     * @return the category
     */
    @Column(name="WE_CATEGORY", nullable=false, length=255, unique=true)
    public String getCategory() {
        return category;
    }

    /**
     * Set category text
     * 
     * @param category - category text
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * Get category posts
     * 
     * @return the posts
     */
    @OneToMany(mappedBy="category")
    public Set<Post> getPosts() {
        return posts;
    }

    /**
     * Set category posts
     * 
     * @param posts - all posts for this is category
     */
    public void setPosts(Set<Post> posts) {
        this.posts = posts;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + (int) (id ^ (id >>> 32));
	return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Category other = (Category) obj;
	if (id != other.id)
	    return false;
	return true;
    }
 
}
